////////////////////////////////
//
// RIGHT NOW ----
// this doesn't seem to work.
//
// A real shame! since badge support is key to success on Kong. 
//
////////////////////////////////

class KongregateSupport
{

	public static var kongregate : Dynamic;
	public static var loader : flash.display.Loader;

	public static function start()
	{
		var paramObj = flash.Lib.current.root.loaderInfo.parameters;

		// Load the API
		try
		{
			var api_url = paramObj.api_path;
			var request = new flash.net.URLRequest ( api_url );
			loader = new flash.display.Loader();
			loader.contentLoaderInfo.addEventListener 
				( flash.events.Event.COMPLETE, loadComplete );
			loader.load ( request );
		}
		catch(d : Dynamic) // fail silently
		{}

	}

	public static function loadComplete ( event:flash.events.Event )
	{
		// Save Kongregate API reference
		kongregate = event.target.content;

		// Connect
		kongregate.services.connect();

		// Debug our services
		trace ( "\n" + kongregate.services );
		trace ( "\n" + kongregate.user );
		trace ( "\n" + kongregate.scores );
		trace ( "\n" + kongregate.stats );
	}

	public static function gameover()
	{
		// send stats here
	}

}
